-- Pierwotny właściciel i twórca kodu: AmaMa
-- Zakaz używania / edycji kodu bez wcześniejszej zgody ze strony właściciela
-- Zakaz wykorzystywania całego lub fragmentów kodu
-- W przypadku złamania powyzszych zasad sprawa zostanie skierowana do sądu pod zarzutem: Naruszenia majątkowych praw autorskich
-- Pierwotnie pełne prawo do używania tego kodu posiada tylko AmaMa

mojeW,mojeH = 1360,768
sW,sH = guiGetScreenSize()
sx, sy = (sW/mojeW), (sH/mojeH)
launchcontrol = false

function gui()
    dxDrawRectangle(1140*sx, 500*sy, 200*sx, 34*sy,(tocolor (128,128,128,140) or tocolor (0,255,0,255)), false)
    progress = (getTickCount() - start)/3000
    local rectWidth = interpolateBetween(0, 0, 0, 200, 0, 0, progress, "Linear")
    dxDrawRectangle(1140*sx, 500*sy, sx*rectWidth, 34*sy,(tocolor (100,0,255,140) or tocolor (0,255,0,255)), false)
	dxDrawText("Launch Control", 1140*sx*2,490*sy*2,200*sx,55*sy, tocolor(255, 255, 255, 255), 1, "default-bold", "center", "center", false, false, false, false, false)
    if not isPedInVehicle(localPlayer) then
        removeEventHandler("onClientRender", root, gui)
		launchcontrol = false    
    end
    if progress >= 1 and getKeyState("space") == false then
	    local veh = getPedOccupiedVehicle(getLocalPlayer())
        removeEventHandler("onClientRender", root, gui)
        launchcontrol = false
        triggerServerEvent("DriveLaunch",getLocalPlayer(),veh)
        return
    end	
end



bindKey("space", "down", function()
    local veh = getPedOccupiedVehicle(getLocalPlayer())
    if veh then
	if getElementData(localPlayer,"nazero") then return end
	if getVehicleController(veh) ~= localPlayer then return end
    if isElementFrozen(veh) then return end
    if not isPedInVehicle(localPlayer) then return end
        if getElementData(veh,"vehicle:data") and getElementData(veh,"vehicle:data").launchcontrol == 1 then
            local sx,sy,sz = getElementVelocity(veh)
            local kmh = ((sx^2+sy^2+sz^2)^(0.5)) * 115
            if kmh < 5 then
                if getKeyState("w") then
                    start = getTickCount()
                    addEventHandler("onClientRender",getRootElement(),gui)
					launchcontrol = true
                end
            end
        end
    end
end)
bindKey("space", "up", function()
    local veh = getPedOccupiedVehicle(getLocalPlayer())
    if veh then
        if getElementData(veh,"vehicle:data") and getElementData(veh,"vehicle:data").launchcontrol == 1 then
            if getKeyState("w") then
                setTimer(function()
                removeEventHandler("onClientRender", root, gui)
                launchcontrol = false
                end,100,1)
            end
        end
    end
end)

bindKey("w", "up", function()
    local veh = getPedOccupiedVehicle(getLocalPlayer())
    if veh then
        if getElementData(veh,"vehicle:data") and getElementData(veh,"vehicle:data").launchcontrol == 1 then
            if getKeyState("space") then
                setTimer(function()
                removeEventHandler("onClientRender", root, gui)
                launchcontrol = false
                end,100,1)
            end
        end
    end
end)


